<template>
    <div class="top">
        <div class="left">
            <span class="lbtn" @click="goHome">首页
            </span>
        </div>
        <div class="center">
            <div class="title">智慧旅游可视化大数据</div>
        </div>
        <div class="right">
            <span class="right_btn">统计报告</span>
            <span class="time">{{ time }}</span>
        </div>
    </div>
</template>
<script setup lang='ts'>
import { ref, onMounted, onBeforeUnmount } from 'vue'
// 引入路由对象
import { useRouter } from 'vue-router';
// 引入时间插件moment
import moment from 'moment'
// 获取路由对象
let router = useRouter()
// 存储定时更新时间的定时器
let timer = ref(0)
// 引入当前时间
let time = ref(moment().format('YYYY年MM月DD日 hh-mm-ss'));
// 跳转首页的回调
const goHome = () => {
    router.push('/home')
}
// 组件挂载即开始更新当前时间
onMounted(() => {
    timer.value = setInterval(() => {
        time.value = moment().format('YYYY年MM月DD日 hh:mm:ss');
    }, 1000);
})
// 组件销毁时关闭定时器
onBeforeUnmount(() => {
    clearInterval(timer.value)
})
</script>
<style lang='scss' scoped>
.top {
    width: 100%;
    height: 40px;
    display: flex;

    .left {
        flex: 1;
        background: url(../../images/dataScreen-header-center-bg.png) no-repeat;
        background-size: cover;
        line-height: 40px;

        .lbtn {
            width: 100px;
            height: 40px;
            float: right;
            background: url(../../images/dataScreen-header-btn-bg-l.png) no-repeat;
            background-size: cover;
            text-align: center;
            color: #29fcff;
        }
    }

    .center {
        flex: 2;

        .title {
            width: 100%;
            height: 74px;
            font-size: 20px;
            background: url(../../images/dataScreen-header-center-bg.png) no-repeat;
            background-size: 100% 100%;
            text-align: center;
            line-height: 74px;
            color: #29fcff;
        }
    }

    .right {
        flex: 1;
        background: url(../../images/dataScreen-header-right-bg.png) no-repeat;
        background-size: 100% 100%;
        display: flex;
        justify-content: space-between;
        line-height: 40px;


        .right_btn {
            width: 100px;
            height: 40px;
            float: left;
            background: url(../../images/dataScreen-header-btn-bg-r.png) no-repeat;
            background-size: cover;
            text-align: center;
            color: #29fcff;
        }

        .time {
            color: #29fcff;
            margin-right: 10px;
        }
    }

}
</style>